package web.servlet.zy5.register.dao;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import web.servlet.zy5.register.domin.User;
import web.servlet.zy5.register.util.JDBCUtils;

/**
 * @Author: 18148
 * @Date: 2020-05-30 15:51:03
 */
public class UserDaoImpl implements UserDao {
    JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
    String sql = "";

    @Override
    public int register(String username, String password) {
        sql = "insert into user(username,password) values(?,?)";
        return template.update(sql, username, password);
    }

    @Override
    public User selectByName(String username) {
        sql="select* from user where username=?";
        try {
            User user = template.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), username);
            return user;
        }
        catch (Exception e){
            System.out.println(e.getMessage());
            return null;
        }
    }
}

